﻿using System;
using System.Collections.Generic;
using DevExpress.XtraEditors.DXErrorProvider;
using Loki.UI;
using Loki.UI.Win;
using Luna.UI.Install;

namespace Luna.UI.Win.Install
{
    /// <summary>
    /// First user creation view.
    /// </summary>
    public partial class FirstUserView : LunaView, IView<FirstUserViewModel>
    {
        public FirstUserView()
        {
            InitializeComponent();
            BindingChanged += InitializeBindings;
        }

        public new FirstUserViewModel ViewModel
        {
            get { return (FirstUserViewModel)base.ViewModel; }
            set { base.ViewModel = value; }
        }

        private void InitializeBindings(object P_Sender, EventArgs e)
        {
            TXT_Nom.BindValue(ViewModel, x => x.Name);
            TXT_Login.BindValue(ViewModel, x => x.Login);
            TXT_Surname.BindValue(ViewModel, x => x.SurName);
            TXT_Password.BindValue(ViewModel, x => x.Password);
            TXT_Confirm.BindValue(ViewModel, x => x.Confirm);
        }

        private void BTN_Ok_Click(object P_Sender, EventArgs e)
        {
            IfValid(ViewModel.CreateUser);
        }

        private void BTN_Cancel_Click(object P_Sender, EventArgs e)
        {
            ViewModel.Cancel.Execute(null);
        }

        protected override IEnumerable<DXValidationProvider> Validators
        {
            get
            {
                return new DXValidationProvider[] { VAL_Required, VAL_Confirm };
            }
        }
    }
}
